import Vue from 'vue'
import Router from 'vue-router'
// in development-env not use lazy-loading, because lazy-loading too many pages will cause webpack hot update too slow. so only in production use lazy-loading;
// detail: https://panjiachen.github.io/vue-element-admin-site/#/lazy-loading

Vue.use(Router)

/* Layout */
import Layout from '../views/layout/Layout'

/**
 * hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
 *                                if not set alwaysShow, only more than one route under the children
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noredirect           if `redirect:noredirect` will no redirct in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
 title: 'title'               the name show in submenu and breadcrumb (recommend set)
 icon: 'svg-name'             the icon show in the sidebar,
 }
 **/

//所有权限通用路由表
//如首页和登录页和一些不用权限的公用页面
export const constantRouterMap = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true,
  },
  {
    path: '/error/401',
    component: () => import('@/views/error/401'),
    hidden: true,
  },
  {
    path: '/error/404',
    component: () => import('@/views/error/404'),
    hidden: true,
  },
  {
    path: '',
    component: Layout,
    name: 'Index',
    // hidden: true,
    children: [
      {
        path: '/',
        name: 'Dashboard',
        meta: { title: '首页', icon: 'dashboard', affix: true },
        component: () => import('@/views/dashboard/index'),
      },
    ],
  },
  {
    path: '',
    component: Layout,
    name: 'Info',
    hidden: true,
    children: [
      {
        path: '/info',
        component: () => import('@/views/info/index'),
      },
    ],
  },
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path*',
        component: () => import('@/views/redirect/index'),
      },
    ],
  },
]

//实例化vue的时候只挂载constantRouter
export default new Router({
  mode: 'history',
  routes: constantRouterMap,
})

//异步挂载的路由
//动态需要根据权限加载的路由表
//meta无permissions字段则不做权限控制
export const asyncRouterMap = [
  {
    path: '',
    component: Layout,
    alwaysShow: true,
    name: 'AppClient',
    meta: {
      title: '账户管理',
      permissions: ['admin', 'appClientList', 'channelList'],
      icon: 'users',
    },
    children: [
      {
        path: '/app-client/accountLog',
        name: 'AppClientAccountLog',
        component: () => import('@/views/appClient/accountLog'),
        meta: {
          title: '账户明细',
          permissions: ['admin', 'appClientAccountLog'],
        },
      },
      {
        path: '/app-client/quotaAccountLog',
        name: 'AppClientQuotaAccountLog',
        component: () => import('@/views/appClient/quotaAccountLog'),
        meta: {
          title: '额度明细',
          permissions: ['admin', 'appClientQuotaAccountLog'],
        },
      },
      {
        path: '/ledgerLogDetail',
        name: 'LedgerLogDetail',
        component: () => import('@/views/order/ledgerLogDetail'),
        meta: { title: '客户对账', permissions: ['admin', 'ledgerLogDetail'] },
      },
    ],
  },
  {
    path: '',
    component: Layout,
    alwaysShow: true,
    name: 'AdminManagement',
    meta: {
      title: '行政管理',
      icon: 'dd',
      permissions: ['admin', 'AdminManagement'],
    },
    children: [
      {
        path: 'rankList',
        name: 'RankList',
        component: () => import('@/views/adminManagement/rankList'),
        meta: {
          title: '职级列表',
          permissions: ['admin', 'rankList'],
        },
      },
      {
        path: 'deptList',
        name: 'DeptList',
        component: () => import('@/views/adminManagement/deptList'),
        meta: {
          title: '部门列表',
          permissions: ['admin', 'deptList'],
        },
      },
      {
        path: 'viewemployee',
        name: 'Viewemployee',
        hidden: true,
        component: () => import('@/views/adminManagement/viewemployee'),
        meta: {
          title: '查看员工',
          permissions: ['admin', 'viewemployee '],
        },
      },
      {
        path: 'staffList',
        name: 'StaffList',
        component: () => import('@/views/adminManagement/staffList'),
        meta: {
          title: '员工列表',
          permissions: ['admin', 'staffList'],
        },
      },
      {
        path: 'staffApplyAudit',
        name: 'StaffApplyAudit',
        component: () => import('@/views/adminManagement/staffApplyAudit'),
        meta: {
          title: '员工申请审核',
          permissions: ['admin', 'staffApplyAudit'],
        },
      },
    ],
  },
  {
    path: '',
    component: Layout,
    alwaysShow: true,
    name: 'MemberCompany',
    meta: {
      title: '成员公司管理',
      icon: 'dd',
      permissions: ['admin', 'memberCompanyList'],
    },
    children: [
      {
        path: '/membercompany/list',
        name: 'MemberCompanyList',
        component: () => import('@/views/membercompany/list'),
        meta: {
          title: '成员列表',
          permissions: ['admin', 'memberCompanyList'],
        },
      },
      {
        path: '/membercompany/financeDetail',
        name: 'financeDetail',
        component: () => import('@/views/membercompany/financeDetail'),
        meta: {
          title: '成员财务',
          permissions: ['admin', 'financeDetail'],
        },
      },
    ],
  },
  {
    path: '',
    component: Layout,
    alwaysShow: true,
    name: 'memberreconciliation',
    meta: {
      title: '成员对账',
      icon: 'dd',
      permissions: ['admin', 'memberreconciliation'],
    },
    children: [
      {
        path: '/memberreconciliation/orderlist',
        name: 'orderlist',
        component: () => import('@/views/memberreconciliation/orderlist'),
        meta: {
          title: '订单列表',
          permissions: ['admin', 'orderlist'],
        },
      },
      {
        path: '/memberreconciliation/reconciliationlist',
        name: 'reconciliationlist',
        component: () =>
          import('@/views/memberreconciliation/reconciliationlist'),
        meta: {
          title: '成员对账列表',
          permissions: ['admin', 'reconciliationlist'],
        },
      },
    ],
  },

  {
    path: '',
    component: Layout,
    alwaysShow: true,
    name: 'Order',
    meta: {
      title: '订单管理',
      icon: 'dd',
      permissions: ['admin', 'orderList'],
    },
    children: [
      {
        path: '/orderList',
        name: 'OrderList',
        component: () => import('@/views/order/orderList'),
        meta: { title: '订单列表', permissions: ['admin', 'orderList'] },
      },
      {
        path: '/orderDetail',
        name: 'OrderDetail',
        component: () => import('@/views/order/orderDetail'),
        meta: { title: '订单明细', permissions: ['admin', 'orderDetail'] },
        hidden: true,
      },
    ],
  },
  {
    path: '',
    component: Layout,
    alwaysShow: true,
    name: 'Admin',
    meta: {
      title: '管理员设置',
      permissions: ['admin', 'adminList'],
      icon: 'system',
    },
    children: [
      {
        path: '/admin/list',
        name: 'Admin',
        component: () => import('@/views/admin/index'),
        meta: { title: '管理员列表', permissions: ['admin', 'adminList'] },
      },
    ],
  },
  { path: '*', redirect: '/error/404', hidden: true },
]
